<?php

class Index_Model extends Model
{
	
	public function __construct()
	{
        parent::__construct();
	}
    
    
    /**
    * get all portfolio works from databases
    * 
    */
    public function getAllPortfolioWorks()
    {
        $sth = $this->db->prepare('select name_work, foto_work, desc_work, link_work from portfolio');
        $sth->execute();
        return $sth->fetchAll();
    }
    
    
    /**
    *  admin section
    *  
    *  save new work in the databases
    */
    public function  admin_add_save($data)
    {
         $res = $this->db->insert('portfolio', array(
            'name_work' => isset($data['name_work'])? $data['name_work'] : '',
            'foto_work' => isset($data['foto_work'])? $data['foto_work'] : '',
            'desc_work' => isset($data['editor1'])? $data['editor1'] : '',
            'link_work' => isset($data['link_work'])? $data['link_work'] : ''
        )); 
        
        if($res)
        {
            header('location: ' . URL . 'portfolio/admin_index');
        } else {
            die('insert error');
        }
        
        
    }
}